package com.lwm.killer.controller;

import com.lwm.killer.result.CodeMsg;
import com.lwm.killer.result.Result;
import com.lwm.killer.service.UserService;
import com.lwm.killer.vo.LoginVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @Author:lwenm
 * @Description
 * @Date:2018/6/8
 * @Time:16:51
 */
@Slf4j
@Controller
@RequestMapping(value = "/login")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping(value = "/to_login")
    public String toLogin(){
        return  "login";
    }

    @RequestMapping(value = "/do_login")
    @ResponseBody
    public Result<Boolean> doLogin(HttpServletResponse response, @Valid LoginVo loginVo){
        log.info(loginVo.toString());

//        String passInput = loginVo.getPassword();
//        String mobile = loginVo.getMobile();
//        if(StringUtils.isEmpty(passInput)){
//            return Result.error(CodeMsg.PASSWORD_EMPTY);
//        }  else if(StringUtils.isEmpty(mobile)){
//            return Result.error(CodeMsg.MOBILE_EMPTY);
//        }else if(!ValidatorUtil.isMobile(mobile)){
//            return Result.error(CodeMsg.MOBILE_ERROR);
//        }

        //登陆开始
        CodeMsg msg = userService.login(response,loginVo);
        if(msg.getCode()==0){
            return Result.success(true);
        }else {
            return Result.error(msg);
        }

    }





}
